<!--
  Created by IntelliJ IDEA.
  User: Dai
  Date: 2018/4/11
  Time: 10:51
  Remark: 工程配置 -  对象管理 -  项目管理
  To change this template use File | Settings | File Templates.
-->
<html layout:decorate="~{project/objectManage/object_list}" xmlns:layout="http://www.w3.org/1999/xhtml"  xmlns:th="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<div layout:fragment="object_list">
    <div class="main-body">
        <div id="toolbar" class="btn-group btn-group-sm " >
            <a type="button" class="btn btn-success" data-toggle="modal"
               href="/project/objectManage/add_project" data-target="#modal2">新增</a>
            <a type="button" class="btn btn-info" onclick="editData('/project/objectManage/add_project','id')">修改</a>
            <a type="button" class="btn btn-danger" onclick="delDatas('/project/objectManage/delete_project')">删除</a>
            <a type="button" class="btn btn-primary" onclick="projectEdit('/project/objectManage/project_edit', 'id', null, 'dataTable')">编辑</a>
        </div>
        <table id="dataTable" data-url="/project/objectManage/project_data" data-page-list=[]  data-striped="true"
               data-pagination="true" data-page-size="10" data-cache="false" data-toolbar-align="right">
        </table>
        <script>
            var dataFormat_project = [{
                checkbox: true
            },{
                field:'id',
                title:'id',
                visible:false
            },{
                title: '序号',
                formatter: function (value, row, index) {
                    return index + 1; // 第一行自然排序
                },
                sortable:true

            },{
                field: 'name',
                title: '名称',
                sortable:true
            },{
                field: 'firstJoinTime',
                title: '首次接入时间',
                formatter: function (value, row, index) {
                    if (value){
                        var unixTimestamp = new Date(value) ;
                        return unixTimestamp.toLocaleDateString();
                    } else {
                        return null;
                    }
                },
                sortable:true
            }, {
                field: 'status',
                title: '状态',
                sortable:true
            }, {
                field: 'onlineDuration',
                title: '在线时长',
                sortable:true
            }, {
                field: 'ip',
                title: 'IP',
                sortable:true
            }, {
                field: 'uploadCycle',
                title: '上传周期(分钟)',
                sortable:true
            }];
            window.onload = function () {
                getTable(dataFormat_project, "dataTable");
            };

            //编辑按钮
            function projectEdit(url, field, id, idResult) {
                if(id){
                    idResult = id;
                }
                var table = $("#"+idResult).bootstrapTable('getSelections');
                if(table.length == 0){
                    alert("请选择一条记录");
                    return false;
                }else if(table.length > 1){
                    alert("只能选择一条记录");
                    return false;
                }
                var result = table[0][field];
                $("#modal1").modal({
                    remote:url+ "?"+field+"="+result
                });
            }
        </script>
    </div>
</div>
</body>
</html>

